package tests;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import terms.Function;

/**
 * 31 mars 2012 Ecole des Mines de Nantes Major in Information and
 * Communications Systems Engineering.
 * @author Pierre Reliquet, Simon Devineau
 */
public class FunctionTest extends TestCase {
    /**
     * The empty function to perform the test.
     */
    private Function      f1;
    /**
     * The function with a 2-arity to perform the test.
     */
    private Function      f2;
    /**
     * The function with a 2-arity to perform the test.
     */
    private Function      f3;

    @Override
    @Before
    protected void setUp() throws Exception {
        this.f1 = new Function();
        this.f2 = new Function("f2", 2);
        this.f3 = new Function("f2", 2);
    }

    @Override
    @After
    protected void tearDown() throws Exception {
        this.f1 = null;
        this.f2 = null;
        this.f3 = null;
    }

    /**
     * Test method for {@link terms.Function#equals(java.lang.Object)}.
     */
    @Test
    public void testEqualsObject() {
        assertEquals(this.f2, this.f3);
        assertFalse(f2.equals(f1));
        assertFalse(f2.equals(1));
    }

    /**
     * Test method for {@link terms.Function#Function()}.
     */
    @Test
    public void testFunction() {
        Assert.assertTrue(this.f1.getFunctionName().equals("")
                && this.f1.getArity() == 0);
    }

    /**
     * Test method for {@link terms.Function.Function(String, Integer)}.
     */
    @Test
    public void testFunctionWithParameters() {
        Assert.assertTrue(this.f2.getFunctionName().equals("f2")
                && this.f2.getArity() == 2);
    }

    /**
     * Test method for {@link terms.Function#getArity()}.
     */
    @Test
    public void testGetArity() {
        assertTrue(this.f2.getArity() == 2);
    }

    /**
     * Test method for {@link terms.Function#getFunctionName()}.
     */
    @Test
    public void testGetFunctionName() {
        Assert.assertTrue("The method getFunctionName does"
                + " not return the name of the function", this.f2
                .getFunctionName().equals("f2"));
    }

    /**
     * Test method for {@link terms.Function#setArity(java.lang.Integer)}.
     */
    @Test
    public void testSetArity() {
        this.f1.setArity(Constants.FOUR);
        Assert.assertTrue(Constants.FOUR == this.f1.getArity());
    }

    /**
     * Test method for {@link terms.Function#setFunctionName(java.lang.String)}.
     */
    @Test
    public void testSetFunctionName() {
        this.f1.setFunctionName("newName");
        Assert.assertEquals("newName", this.f1.getFunctionName());
    }

    /**
     * Test method for {@link terms.Function#toString()}.
     */
    @Test
    public void testToString() {
        Assert.assertEquals(this.f2.toString(), "f2 with 2 parameters");
    }
}
